import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * I am a Cuchillo
 * @author Hugo Armando Rodriguez Flores 
 * @version April 25th 2013
 */
public class Cuchillo extends Actor
{
    private boolean direction;  //This is direction is going to take the knife
    private GreenfootImage img; //The image the knife is going to take
    
    /**
     * Sets the properties for objects of class Cuchillo
     * @param aDirection is a directions that is taken from Buck when he throws a knife
     */
    public Cuchillo(boolean aDirection)
    {
        img=new GreenfootImage("knife.png");
        direction=aDirection;
        if (direction)
            img.mirrorHorizontally();
        this.setImage(img);
    }
    
    /**
     * This makes the knife move and dissapear
     */
    public void act() 
    {
        this.move();
        this.knifeDissapear();
    }
    
    /**
     * This deletes the knife from the world when it touches the limits of the screen
     */
    public void knifeDissapear()
    {
        World world=getWorld();
        if (this.getX()==0 || this.getX()==world.getWidth()-1)
            world.removeObject(this);
    }
    
    /**
     * This makes the knife move depending on the direction
     */
    public void move()
    {
        if (direction)
            this.setLocation(this.getX()+1, this.getY());
        else
            this.setLocation(this.getX()-1, this.getY());
    }
}
